package com.nbsaas.boot.cms.rest.convert;

import com.nbsaas.boot.cms.data.entity.News;
import com.nbsaas.boot.cms.api.domain.request.NewsRequest;

import org.springframework.beans.BeanUtils;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;
            import com.nbsaas.boot.jpa.data.entity.User;
            import com.nbsaas.boot.cms.data.entity.NewsCatalog;

/**
* 新闻请求对象转换成实体对象
*/

public class NewsEntityConvert  implements Converter<News, NewsRequest> {

    @Override
    public News convert(NewsRequest source) {
        News result = new News();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getCreator()!=null){
                    User creator =new User();
                    creator.setId(source.getCreator());
                    result.setCreator(creator);
                    }
                    if(source.getNewsCatalog()!=null){
                    NewsCatalog newsCatalog =new NewsCatalog();
                    newsCatalog.setId(source.getNewsCatalog());
                    result.setNewsCatalog(newsCatalog);
                    }
        return result;
    }
}

